const { createClient } = require('redis')

let client

async function getRedisClient() {
  if (!client) {
    client = createClient({
      host: process.env.REDIS_HOST,
      port: process.env.REDIS_PORT,
      password: process.env.REDIS_PASSWORD,
    })
    
    client.on('error', (err) => {
      console.error('Redis连接错误:', err)
    })
    
    await client.connect()
  }
  return client
}

module.exports = {
  getRedisClient
}
